from backTest import oneTest
import pandas as pd
class cal(object):
    input=pd.read_csv('input.csv')
    @classmethod
    def cal_one(cls,index):
        row=cls.input.iloc[index]
        code=row['code']
        begin=row['beginDate']
        end=row['endDate']
        k=row['K']
        nominal=row['nominal']
        caler=oneTest(code,begin,end,nominal,k)
        delta,prices,delta_pnl,option_pnl=caler.deltaPNL()
        row['delta_pnl']=delta_pnl.sum()
        row['option_pnl']=prices[0]-prices[-1]
        row['max_error']=max(abs(delta_pnl-option_pnl))/nominal
        row['mean_error']=(abs(delta_pnl-option_pnl).mean())/nominal
        return row
    @classmethod
    def cal_all(cls,begin=None,max_row=None):
        if max_row is None:
            max_row=cls.input.shape[0]
        if begin is None:
            begin=0
        df=pd.DataFrame()
        for index in range(begin,max_row):
            print(index)
            result=cls.cal_one(index)
            df=df.append(result)
        return df

if __name__=="__main__":
    df=cal.cal_all()
    pass
    